using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;

public class ShowButton : MonoBehaviour
{
    public TMP_Text tMP_Text;
    private string text;
    private float origin_weight;
    private Vector2 button_size;
    private float weight = 0f;
    // Start is called before the first frame update
    void Start()
    {
        text = tMP_Text.text;
        origin_weight = GetComponent<RectTransform>().sizeDelta.x;
        button_size = GetComponent<RectTransform>().sizeDelta;
        print(origin_weight + " " + text);
        button_size.x = weight;
        GetComponent<RectTransform>().sizeDelta = button_size;
        tMP_Text.text = "";
    }

    int count = 0;
    // Update is called once per frame
    void Update()
    {
        int n = 36;
        if (count / n < text.Length + 1)
        {
            tMP_Text.text = text.Substring(0, count / n);
            count++;
        }
        if (origin_weight - weight > 0.1)
        {
            weight += (origin_weight - weight) * 0.02f;
            button_size.x = weight;
            GetComponent<RectTransform>().sizeDelta = button_size;
        }
        else
        {
            button_size.x = origin_weight;
            GetComponent<RectTransform>().sizeDelta = button_size;
        }
    }
}
